<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/7/25
 * Time: 14:37
 */

namespace app\common\model;


use think\Model;

class Post extends Model
{
    protected $autoWriteTimestamp = true;

    // 关联item表
    public function category()
    {
        return $this->hasOne('Category','id','type_id');
    }

    public function postcontent()
    {
        return $this->hasOne('PostContent','post_id','id')->bind('post_id,content');
    }

    /**
     * 获取详细信息
     * @param  milit   $id 分类ID或标识
     * @param  boolean $field 查询字段
     * @return array     分类信息
     */
    public function info($id, $field = true){
        /* 获取分类信息 */
        $map = array();
        if(is_numeric($id)){ //通过ID查询
            $map['id'] = $id;
        } else { //通过标识查询
            $map['title'] = $id;
        }
        return Post::field($field)->where($map)->find();
    }
}